package com.example.barcodescanner;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


public class CallActivity extends Activity{
	Button pCall;
	EditText PhoneNumber;
	
	public void onCreate(Bundle savedInstanceState) 
	    {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.activity_call);
	        
		pCall = (Button) findViewById(R.id.pCall);
		PhoneNumber = (EditText) findViewById(R.id.PNo);
		
		pCall.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				String pNo = PhoneNumber.getText().toString();
				
				if (pNo.length() > 0)
				call(pNo);
				else
					Toast.makeText(getBaseContext(),
							"Enter both phone number.",
							Toast.LENGTH_SHORT).show();
			}
			private void call(String pNo) {
			    try {
			    	
			        Intent callIntent = new Intent(Intent.ACTION_CALL);
			        callIntent.setData(Uri.parse("tel:"+pNo));
			      
			       startActivity(callIntent);
			    } catch (ActivityNotFoundException activityException) {
			        Log.e("dialing-example", "Call failed", activityException);
			    }
			}
		});
	    }
}



	
